package com.baiyinet.ui;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Window;

import com.baiyinet.R;
import com.baiyinet.biz.PageStatus;
import com.baiyinet.ui.general.GeneralActivity_;
import com.flyco.dialog.listener.OnBtnClickL;
import com.flyco.dialog.widget.NormalDialog;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Fullscreen;
import org.androidannotations.annotations.WindowFeature;
import org.parceler.Parcels;


@Fullscreen
@WindowFeature({Window.FEATURE_NO_TITLE})
@EActivity(R.layout.activity_push_msg_dialog)
public class PushMsgDialogActivity extends Activity {

    private NormalDialog mDialog;

    @AfterViews
    void initUI() {
        final PageStatus pageStatus = Parcels.unwrap(getIntent().getParcelableExtra(PageStatus.EXTRA_NAME));

        mDialog = new NormalDialog(this);

        mDialog.isTitleShow(false)
                .btnNum(2)
                .bgColor(Color.parseColor("#FFFFFF"))
                .cornerRadius(5)
                .content("有新的推送消息！是否显示？")
                .contentGravity(Gravity.CENTER)
                .contentTextSize(13)
                .contentTextColor(Color.parseColor("#333333"))
                .dividerColor(Color.parseColor("#CCCCCC"))
                .btnText("忽略", "显示")
                .btnTextSize(15.5f, 15.5f)
                .btnTextColor(Color.parseColor("#333333"), Color.parseColor("#0092FF"))
                .widthScale(0.7f)
                .show();

        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setCancelable(false);

        mDialog.setOnBtnClickL(
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {
                        mDialog.dismiss();
                        PushMsgDialogActivity.this.finish();
                    }
                },
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {
                        Intent newIntent = new Intent();
                        newIntent.setClass(PushMsgDialogActivity.this, GeneralActivity_.class);
                        newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                        newIntent.putExtra(PageStatus.EXTRA_NAME, Parcels.wrap(pageStatus));
                        PushMsgDialogActivity.this.startActivity(newIntent);
                        mDialog.dismiss();
                        PushMsgDialogActivity.this.finish();
                    }
                });
    }

    @Override
    protected void onDestroy() {
        if (mDialog != null) {
            mDialog.superDismiss();
            mDialog = null;
        }
        super.onDestroy();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            onBackPressed();
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onBackPressed() {}
}
